/*
 * Copyright 2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package be.free.ts.contact;

import com.google.common.base.Strings;
import com.mysema.query.BooleanBuilder;
import com.mysema.query.types.Predicate;

/**
 * @author Christophe De Blende
 * @since 30/12/12
 */
public final class Contacts {

	private Contacts() {
	}

	public static Predicate withSsin(final String inss) {
		return QContact.contact.ssin.eq(inss);
	}

	public static Predicate byExample(final String ssin, final String firstName, final String lastName) {
		BooleanBuilder predicate = new BooleanBuilder();
		if (!Strings.isNullOrEmpty(ssin)) {
			predicate.and(QContact.contact.ssin.contains(ssin));
		}
		if (!Strings.isNullOrEmpty(firstName)) {
			predicate.and(QContact.contact.firstName.contains(firstName));
		}

		if (!Strings.isNullOrEmpty(lastName)) {
			predicate.and(QContact.contact.lastName.contains(lastName));
		}

		return predicate;

	}

}
